home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/perl
- # make-SOA - Generate a DNS SOA record for a domain
- #
- # $Id: soa-easy.shar,v 8.2 1996/10/25 17:08:00 vixie Exp $
- # $Source: /proj/src/isc/cvs-1/bind/contrib/misc/soa-easy.shar,v $
- #
- # SYNOPSIS
- # make-SOA -o SOA-file domain-file
-
-
- #
- # Values for the SOA record. See RFC1035 for info.
- #
-
- #
- # The <domain-name> of the name server that was the original or
- # primary source of data for this zone.
- $SOA_MNAME = 'ns.example.org.au.';
-
- #
- # A <domain-name> which specifies the mailbox of the person
- # responsible for this zone
- $SOA_RNAME = 'hostmaster.example.org.au.';
-
- #
- # A 32 bit time interval (in seconds) before the zone should be
- # refreshed
- $SOA_REFRESH = 10800; # 3 hours
-
- #
- # A 32 bit time interval that should elapse before a failed refresh
- # should be retried
- $SOA_RETRY = 3600; # 1 hour
-
- #
- # A 32 bit time value that specifies the upper limit on the time
- # interval that can elapse before the zone is no longer authoritative.
- $SOA_EXPIRE = 2592000; # 30 days
-
- #
- # The unsigned 32 bit minimum time-to-live field that should be
- # exported with any resource record from this zone.
- $SOA_MINIMUM = 86400; # 24 hours
-
-
- $prog = 'make-SOA';
-
- $usage = 'usage: ' . $prog . ' -o SOA-file domain-file';
-
- if (($#ARGV != 2) || ($ARGV[0] ne '-o')) {
- die $usage . "\n";
- }
-
- $soa_file = $ARGV[1];
- $domain_file = $ARGV[2];
-
-
- #
- # Read current serial number from SOA-file, if any
- #
- if (-f $soa_file) {
- open (SOA, $soa_file) || die "$prog: can't open $soa_file: $!\n";
- while (<SOA>) {
- if (/; -SERIAL- \(make-SOA\)/) {
- s/^\s*//;
- ($old_serial, $dummy) = split;
- last;
- }
- }
- close (SOA);
- if (! length ($old_serial)) {
- warn "$prog: warning: can't find SERIAL in SOA-file\n";
- }
- } else {
- warn "$prog: warning: no existing SOA-file\n";
- }
-
- #
- # Starting with the domain file, read it, obtain any RCS Id keywords,
- # and repeat for any $INCLUDE files
- #
-
- &get_rcs ($domain_file);
-
- #
- # Calculate serial number
- #
-
- #print (join ("\n", "RCS ID data:", @rcs_ids, ""));
-
- #
- # Discard all but the date
- foreach (@rcs_ids) {
- s/^\s*//;
- @fields = split;
- $_ = $fields[2];
- }
-
- @rcs_ids = sort (@rcs_ids);
- $most_recent = pop (@rcs_ids);
- $most_recent =~ s/\///g; # Remove slashes
-
- #
- # Sanity check
- #
- if (! ($most_recent =~ /^[0-9]+$/)
- || ($most_recent > 99999999))
- {
- die "$prog: generated SERIAL is too big\n";
- }
-
- $serial = $most_recent * 100;
-
- while (1) {
- last if ($serial > $old_serial);
- $serial++;
- if ($serial >> 9999999999) {
- die "$prog: generated SERIAL is too big\n";
- }
- }
-
- #
- # Backup existing SOA-file, if any
- #
- $backup_file = $soa_file . '.backup';
-
- unlink ($backup_file);
- rename ($soa_file, $backup_file);
-
-
- #
- # Write new SOA-file
- #
- open (SOA, '>' . $soa_file) || die "$prog: can't open $soa_file: $!\n";
- print (SOA
- "; $soa_file - SOA record for inclusion in $domain_file
- ;
- ; NOTE: This file is generated by $prog -- DO NOT EDIT
- ;
- @ IN SOA $SOA_MNAME $SOA_RNAME (
- $serial ; -SERIAL- (make-SOA)
- $SOA_REFRESH ; REFRESH
- $SOA_RETRY ; RETRY
- $SOA_EXPIRE ; EXPIRE
- $SOA_MINIMUM ; MINIMUM
- )
- ") || die "$prog: can't write to $soa_file: $!\n";
- close (SOA) || die "$prog: can't close $soa_file: $!\n";
-
- #
- # Remove backup SOA-file
- #
- unlink ($backup_file);
-
- #
- # EXIT
- #
- exit (0);
-
-
- ###############################################################
- # get_rcs - Obtain RCS Id keywords, handling $INCLUDE files
- #
- # GLOBALS
- # @rcs_ids
- #
- sub get_rcs {
- local ($file_name) = shift (@_);
-
- local ($_);
- local (@includes);
- local (@parts);
-
- open (FILE, $file_name) || die "$prog: can't open $file_name: $!\n";
-
- while (<FILE>) {
- #
- # The [I] is to prevent RCS thinking it is an RCS keyword
- #
- if (/\$[I]d:\s.*$/) {
- $_ = substr ($_, index ($_, '$Id:') + 4);
- s/\$.*\n*$//;
- push (@rcs_ids, $_);
- }
- s/;.*$//;
- if (/\$INCLUDE\s/) {
- @parts = split; $_ = $parts[1];
- if (length ($_) && (! /\.SOA$/)) {
- push (@includes, $parts[1]); }
- }
- }
- close (FILE);
-
- #
- # Recurse on $INCLUDE-ed files
- #
- foreach (@includes) {
- &get_rcs ($_);
- }
- }
-